package com.chinadci.smartcommunitysystembackstage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinadci.smartcommunitysystembackstage.entity.ScsOwner;
import com.chinadci.smartcommunitysystembackstage.entity.ScsPay;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsAdmintypeMapper;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsPayMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@Service
public class ScsPayService{
    @Autowired
    private ScsPayMapper mapper;

    @Autowired
    private ScsOwnerService service;

    private Logger log= LoggerFactory.getLogger(this.getClass());

    //显示所有用户缴费记录
    public List<ScsPay> Find(String name){
        log.info("=====显示所有用户缴费记录");
        List<ScsPay> list=null;
        if (name!="" && name!=null && !name.equals("null")){
            int id=service.finds(name).getOId();
            list= mapper.Finds(id);
        }else{
            list= mapper.Find();
        }
        for (int i = 0; i <list.size(); i++) {
            list.get(i).setName(list.get(i).getOwnerList().get(0).getOName());
            list.get(i).setType(list.get(i).getTypeList().get(0).getPtName());
        }
        return list;
    }


    //删除用户缴费记录
    public int Del(int id){
        log.info("=====删除用户缴费记录");
        QueryWrapper<ScsPay> qw=new QueryWrapper<>();
        qw.eq("p_id",id);
        return mapper.delete(qw);
    }

    //新增缴费记录
    public int Xz(ScsPay scs){
        log.info("=====新增用户缴费记录");
        return mapper.insert(scs);
    }
}
